package com.df.happylearn.sqlite;

import android.content.Context;

import com.df.happylearn.application.MyApplication;
import com.df.happylearn.model.ArticleInfo;
import com.df.happylearn.model.MessageInfo;
import com.df.happylearn.model.MessageRead;

public class DBUtil {
    private Context mContext;

    private BaseDao<ArticleInfo, Integer> mArticleDao;
    private BaseDao<MessageInfo, Integer> mMessageDao;
    private BaseDao<MessageRead, Integer> mMessageReadDao;

    private static DBUtil dbUtil = null;

    public static DBUtil getInstance() {
        if (dbUtil == null) {
            dbUtil = new DBUtil(MyApplication.getInstance());
        }
        return dbUtil;
    }

    public DBUtil(Context context) {
        mContext = context;
    }

    public BaseDao<ArticleInfo, Integer> getArticleDao() {
        if (mArticleDao == null) {
            mArticleDao = new BaseDaoImpl<ArticleInfo, Integer>(mContext, ArticleInfo.class);
        }
        return mArticleDao;
    }

    public BaseDao<MessageInfo, Integer> getMessageDao() {
        if (mMessageDao == null) {
            mMessageDao = new BaseDaoImpl<MessageInfo, Integer>(mContext, MessageInfo.class);
        }
        return mMessageDao;
    }

    public BaseDao<MessageRead, Integer> getMessageReadDao() {
        if (mMessageReadDao == null) {
            mMessageReadDao = new BaseDaoImpl<MessageRead, Integer>(mContext, MessageRead.class);
        }
        return mMessageReadDao;
    }

}
